//多态: 胡类型的引用指向了值类型的对象 ,不同类型的对象针对相同的方法 产生了不同的行为
(()=>{
    class Animal{
        name:string
        constructor(name:string) {
            this.name= name
        }
        run(distance:number=0) {
            console.log(`${this.name}跑了${distance}mi`);
            
        }
    }
    class Dog extends Animal {
        constructor(name:string) {
            super(name)
        }
        run(distance:number=5) {
            console.log(`${this.name}跑了${distance}mi`);
            
        }
    }
    class Cat extends Animal {
        constructor(name:string) {
            super(name)
        }
        run(distance:number=10) {
            console.log(`${this.name}跑了${distance}mi`);
            
        }
    }
    const ani:Animal = new Animal('动物')
    ani.run()
    const dog:Dog = new Dog('大黄')
    dog.run()
    const cat:Cat = new Cat('小米')
    cat.run()
    /* 
    父类和子类的关系  可以用父类创建子类的对象
    */
   const dog1:Animal = new Dog('小黄')
   dog1.run()
   const cat1:Animal = new Cat('大牧场')
   cat1.run()
   function showRun(ani:Animal) {
       ani.run()
   }
   showRun(dog1)
   showRun(cat1)
})()